package com.hxh.learn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.core.util.StrUtil;
import com.hxh.learn.model.SysRule;
import com.hxh.learn.mapper.SysRuleMapper;
import com.hxh.learn.model.SysUser;
import com.hxh.learn.service.ISysRuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxh.learn.vo.SysRuleSearchVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 系统角色 服务实现类
 * </p>
 *
 * @author hxh
 * @since 2023-03-02
 */
@Service
public class SysRuleServiceImpl extends ServiceImpl<SysRuleMapper, SysRule> implements ISysRuleService {
    @Resource
    private SysRuleMapper ruleMapper;

    @Override
    public Page<SysRule> queryRuleList(SysRuleSearchVo vo) {
        LambdaQueryWrapper<SysRule> lambdaQuery = Wrappers.lambdaQuery(SysRule.class);
        lambdaQuery.like(StrUtil.isNotBlank(vo.getRoleName()), SysRule::getRoleName, vo.getRoleName())
                .like(StrUtil.isNotBlank(vo.getRoleDoc()), SysRule::getRoleDoc, vo.getRoleDoc())
                .ge(vo.getStartTime() != null, SysRule::getCreateTime, vo.getStartTime())
                .le(vo.getEndTime() != null, SysRule::getCreateTime, vo.getEndTime());
        Page<SysRule> page = new Page<>(vo.getPageNum(), vo.getPageSize());
        return ruleMapper.selectPage(page, lambdaQuery);
    }
}
